gtk/gtkaccelgroup.c: Fix build on Visual Studio
authorChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 28 Apr 2020 16:07:27 +0000 (00:07 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Wed, 29 Apr 2020 07:02:03 +0000 (15:02 +0800)
Visual Studio does not allow one to initialize structure members with
non-constant expressions, caused by using strlen(s), so fix this by
using sizeof(s) - 1 instead.

gtk/gtkaccelgroup.c

index a941b6055c1497d1156a6e70a8a9e899d9a9bf04..b749581629b889a4e444a88d72877789f36f0469 100644 (file)
@@ -574,18 +574,20 @@ char *
 gtk_accelerator_name (guint           accelerator_key,
                       GdkModifierType accelerator_mods)
 {
+#define TXTLEN(s) sizeof (s) - 1
   static const struct {
     guint mask;
     const char *text;
     gsize text_len;
   } mask_text[] = {
-    { GDK_SHIFT_MASK,   "<Shift>",   strlen ("<Shift>") },
-    { GDK_CONTROL_MASK, "<Control>", strlen ("<Control>") },
-    { GDK_ALT_MASK,     "<Alt>",     strlen ("<Alt>") },
-    { GDK_META_MASK,    "<Meta>",    strlen ("<Meta>") },
-    { GDK_SUPER_MASK,   "<Super>",   strlen ("<Super>") },
-    { GDK_HYPER_MASK,   "<Hyper>",   strlen ("<Hyper>") }
+    { GDK_SHIFT_MASK,   "<Shift>",   TXTLEN ("<Shift>") },
+    { GDK_CONTROL_MASK, "<Control>", TXTLEN ("<Control>") },
+    { GDK_ALT_MASK,     "<Alt>",     TXTLEN ("<Alt>") },
+    { GDK_META_MASK,    "<Meta>",    TXTLEN ("<Meta>") },
+    { GDK_SUPER_MASK,   "<Super>",   TXTLEN ("<Super>") },
+    { GDK_HYPER_MASK,   "<Hyper>",   TXTLEN ("<Hyper>") }
   };
+#undef TXTLEN
   GdkModifierType saved_mods;
   guint l;
   guint name_len;